package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.statisticsaa;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QQuestionnaireAnswer;
import com.ruoyi.system.service.IQQuestionnaireAnswerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问卷答案Controller
 * 
 * @author ruoyi
 * @date 2025-04-10
 */
@RestController
@RequestMapping("/system/answer")
public class QQuestionnaireAnswerController extends BaseController
{
    @Autowired
    private IQQuestionnaireAnswerService qQuestionnaireAnswerService;

    /**
     * 查询问卷答案列表
     */
    @PreAuthorize("@ss.hasPermi('system:answer:list')")
    @GetMapping("/list")
    public TableDataInfo list(QQuestionnaireAnswer qQuestionnaireAnswer)
    {
        startPage();
        List<QQuestionnaireAnswer> list = qQuestionnaireAnswerService.selectQQuestionnaireAnswerList(qQuestionnaireAnswer);
        return getDataTable(list);
    }
    @GetMapping("/statistics")
    public HashMap statistics(QQuestionnaireAnswer qQuestionnaireAnswer)
    {
        HashMap<Object, Object> map = new HashMap<>();
        HashMap map11 = qQuestionnaireAnswerService.findstatistics();
        ArrayList<statisticsaa> ss =new ArrayList();
        statisticsaa bb = new statisticsaa();
        bb.setAsum((String)map11.get("grade1A").toString());
        bb.setBsum(map11.get("grade1B").toString());
        bb.setCsum((String)map11.get("grade1C").toString());
        bb.setDsum((String)map11.get("grade1D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade2A").toString());
        bb.setBsum((String)map11.get("grade2B").toString());
        bb.setCsum((String)map11.get("grade2C").toString());
        bb.setDsum((String)map11.get("grade2D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade3A").toString());
        bb.setBsum((String)map11.get("grade3B").toString());
        bb.setCsum((String)map11.get("grade3C").toString());
        bb.setDsum((String)map11.get("grade3D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade4A").toString());
        bb.setBsum((String)map11.get("grade4B").toString());
        bb.setCsum((String)map11.get("grade4C").toString());
        bb.setDsum((String)map11.get("grade4D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade5A").toString());
        bb.setBsum((String)map11.get("grade5B").toString());
        bb.setCsum((String)map11.get("grade5C").toString());
        bb.setDsum((String)map11.get("grade5D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade6A").toString());
        bb.setBsum((String)map11.get("grade6B").toString());
        bb.setCsum((String)map11.get("grade6C").toString());
        bb.setDsum((String)map11.get("grade6D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade7A").toString());
        bb.setBsum((String)map11.get("grade7B").toString());
        bb.setCsum((String)map11.get("grade7C").toString());
        bb.setDsum((String)map11.get("grade7D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade8A").toString());
        bb.setBsum((String)map11.get("grade8B").toString());
        bb.setCsum((String)map11.get("grade8C").toString());
        bb.setDsum((String)map11.get("grade8D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade9A").toString());
        bb.setBsum((String)map11.get("grade9B").toString());
        bb.setCsum((String)map11.get("grade9C").toString());
        bb.setDsum((String)map11.get("grade9D").toString());
        ss.add(bb);
        bb.setAsum((String)map11.get("grade10A").toString());
        bb.setBsum((String)map11.get("grade10B").toString());
        bb.setCsum((String)map11.get("grade10C").toString());
        bb.setDsum((String)map11.get("grade10D").toString());
        ss.add(bb);
        map.put("info",ss);
        return map;
    }

    /**
     * 导出问卷答案列表
     */
    @PreAuthorize("@ss.hasPermi('system:answer:export')")
    @Log(title = "问卷答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QQuestionnaireAnswer qQuestionnaireAnswer)
    {
        List<QQuestionnaireAnswer> list = qQuestionnaireAnswerService.selectQQuestionnaireAnswerList(qQuestionnaireAnswer);
        ExcelUtil<QQuestionnaireAnswer> util = new ExcelUtil<QQuestionnaireAnswer>(QQuestionnaireAnswer.class);
        util.exportExcel(response, list, "问卷答案数据");
    }

    /**
     * 获取问卷答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:answer:query')")
    @GetMapping(value = "/{answerId}")
    public AjaxResult getInfo(@PathVariable("answerId") Long answerId)
    {
        return success(qQuestionnaireAnswerService.selectQQuestionnaireAnswerByAnswerId(answerId));
    }

    /**
     * 新增问卷答案
     */
//    @PreAuthorize("@ss.hasPermi('system:answer:add')")
    @Log(title = "问卷答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QQuestionnaireAnswer qQuestionnaireAnswer)
    {
        return toAjax(qQuestionnaireAnswerService.insertQQuestionnaireAnswer(qQuestionnaireAnswer));
    }

    /**
     * 修改问卷答案
     */
    @PreAuthorize("@ss.hasPermi('system:answer:edit')")
    @Log(title = "问卷答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QQuestionnaireAnswer qQuestionnaireAnswer)
    {
        return toAjax(qQuestionnaireAnswerService.updateQQuestionnaireAnswer(qQuestionnaireAnswer));
    }

    /**
     * 删除问卷答案
     */
    @PreAuthorize("@ss.hasPermi('system:answer:remove')")
    @Log(title = "问卷答案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{answerIds}")
    public AjaxResult remove(@PathVariable Long[] answerIds)
    {
        return toAjax(qQuestionnaireAnswerService.deleteQQuestionnaireAnswerByAnswerIds(answerIds));
    }
}
